package org.laobai.cart.controller;

import org.laobai.cart.entity.Cart;
import org.laobai.cart.service.CartService;
import org.laobai.common.struct.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("cart")
public class CartController {
    @Autowired
    private CartService cartService;
    // 添加购物车
    // 入参 user—id goods-id num
    @PostMapping("/add/{goodsId}/{num}")
    public Result addCart(@PathVariable("goodsId")Long goodsId,@PathVariable("num") Integer num){
        return cartService.addCart(goodsId,num)?Result.ok():Result.error();
    }

    @GetMapping
    public Result<List<Cart>> list(){
        return Result.ok(cartService.list());
    }
}
